package com.innazis.jfrogsurvey;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.innazis.jfrogsurvey.utility.LemonProgressDialog;

public class BaseActivity extends Activity {
	public BaseActivity self;
    private Button btnBack;
	protected LemonProgressDialog progressDialog;
	private boolean isShowDialogNetwork = false;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		self = this;
		progressDialog = new LemonProgressDialog(self);
		progressDialog.setCancelable(false);
	}

//    protected void initHeader() {
//        btnBack = (Button) findViewById(R.id.btnBack);
//        btnBack.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                // TODO Auto-generated method stub
//                onBackHeaderClick();
//            }
//        });
//    }
//    protected void onBackHeaderClick() {
//        finish();
//    }

	protected void showLoading() {
		if (!progressDialog.isShowing())
			progressDialog.show();
	}

	protected void hideLoading() {
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.cancel();
			progressDialog.dismiss();
		}
	}

	@Override
	public void startActivity(Intent intent) {
		super.startActivity(intent);
		overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
	}

	protected void startActivity(Class<?> cls) {
		startActivity(new Intent(this, cls));
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
	}

	protected void showToastLong(String message) {
		Toast.makeText(self, message, Toast.LENGTH_LONG).show();
	}

	protected void showToastLong(int messageId) {
		Toast.makeText(self, messageId, Toast.LENGTH_LONG).show();
	}

	protected void showToast(int messageId) {
		Toast.makeText(self, messageId, Toast.LENGTH_SHORT).show();
	}

	protected void showToast(String messsage) {
		Toast.makeText(self, messsage, Toast.LENGTH_SHORT).show();
	}

	protected void showDialogMessage(Object object) {
		showDialogMessage(String.valueOf(object));
	}

    public void gotoActivity(Context context, Class<?> cla) {
        Intent intent = new Intent(context, cla);
        startActivity(intent);
        overridePendingTransition(R.anim.slide_in_left,
        R.anim.slide_out_left);
    }

    public void gotoActivityForResult(Context context, Class<?> cla,
                                      Bundle bundle, int requestCode) {
        Intent intent = new Intent(context, cla);
        intent.putExtras(bundle);
        startActivityForResult(intent, requestCode);
    }

	public void showDialogNoNetwork(final boolean isFinish) {
		if (!isShowDialogNetwork) {
			new AlertDialog.Builder(this)
					.setIcon(R.drawable.ic_launcher)
					.setTitle(R.string.app_name)
					.setMessage(R.string.message_nonetwork)
					.setCancelable(false)
					.setPositiveButton(android.R.string.ok,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									Intent settings = new Intent(
											android.provider.Settings.ACTION_WIFI_SETTINGS);
									settings.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
									startActivity(settings);
									isShowDialogNetwork = false;
								}
							})
					.setNegativeButton(android.R.string.cancel,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									if (isFinish) {
										finish();
									}
								}
							}).show();
			isShowDialogNetwork = true;
		}
	}
}
